<?php
class Site extends CI_Controller{
	
	function index(){
		$this->load->model('Customer_management');
		$data['siteCode'] = $this->Customer_management->generateSiteCode();
		$data['main_content'] = 'create_site';
		$this->load->view('layouts/general', $data);
	}
	
	function create(){
		$sort = explode('CS',$_POST['siteCode']);
		$site_data = array(
		'siteCode' => $_POST['siteCode'],
		'name' => $_POST['siteName'],
		'address' => $_POST['siteAddress'],
		'postcode' => $_POST['sitePostcode'],
		'sort' => $sort[1],
		'customerCode' => $_POST['customerCode']
		);
		$this->load->model('Customer_management');
		if(!$this->Customer_management->createSite($site_data)){
			$data['success_message'] .= 'Something went wrong while creating the site!';	
		}
		else{
			$data['success_message'] = "Successfully added a site!";
		}		
		$data['main_content'] = 'success_message';
		$this->load->view('layouts/general',$data);
	}
}
?>